home *** CD-ROM | disk | FTP | other *** search
- BEGIN {
- #{{{}}}
- # {{{ gen filenames
- tokout="token.h"
- lgout="codelg.h"
- # }}}
- # {{{ print auto-gen-marks
- print("/* This file is generated automatically by awk -f tok2h.awk */\n/* containing command types for OCL token */") >lgout
- print("/* This file is generated automatically by awk -f tok2h.awk */\n/* containing automatically generated OCL tokens (origami) */") >tokout
- # }}}
- # {{{ print start of token type
- print("#ifndef TOKEN_H_READ") >tokout
- print("# define TOKEN_H_READ") >tokout
- print(" typedef enum") >tokout
- print(" { keytaball = -4,") >tokout
- print(" keytabknb = -3,") >tokout
- print(" keytabend = -2,") >tokout
- print(" keytabcont= -1,") >tokout
- print(" O_NOP=(1<<BITS_P_CHAR),") >tokout
- # }}}
- # {{{ print command type
- print("typedef enum") >lgout
- print(" { COM=0,\t/* simple command\t\t\t*/") >lgout
- print(" COM_C,\t/* command with 1 char argument\t\t*/") >lgout
- print(" COM_I,\t/* command with 1 int argument\t\t*/") >lgout
- print(" COM_A,\t/* command with a adress\t\t*/") >lgout
- print(" COM_II,\t/* command with 2 int arguments\t\t*/") >lgout
- print(" COM_P,\t/* command with a prompt\t\t*/") >lgout
- print(" COM_IP,\t/* command with 1 int and prompt\t*/") >lgout
- print(" COM_IIP\t/* command with 2 int and prompt\t*/") >lgout
- print(" } COM_TYPES;") >lgout
- print("#ifdef CODE_LG_ARRAY") >lgout
- print(" COM_TYPES cmd_type[] =\n { COM,\t\t/* O_NOP */") >lgout
- # }}}
- # {{{ init fixed cmd arg range
- cmd_range=8
- # }}}
- check=0
- }
- #{{{ set fixed cmd arg range
- /^#define +FIXED_COMMAND_RANGE/ {
- cmd_range=$3
- }
- #}}}
- #{{{ skip comments
- $0~/^#/ { next }
- #}}}
- #{{{ OCL-var handling
- #}}}
- #{{{ set types for command and fixed command
- $3=="COM" || $3=="COM_I" || $3=="COM_II" || $3=="COM_P" || $3=="COM_IP" || $3=="COM_IIP" || $3=="COM_C" { typ=$3;fix_typ="" }
- $3=="COM_A" { typ="COM_A";fix_typ="COM" }
- $3=="COM_ID" { typ="COM_II";fix_typ="COM_I"; }
- $3=="COM_D" { typ="COM_I";fix_typ="COM"; }
- #}}}
- #{{{ print token and cmd type
- $3!="OCL-KEY" && $3!="OPP-KEY" {
- if (fix_typ!="") {
- if (def=="")
- def="# define RANGE_ADD ("$1"_0-"$1")\n"
- def=def"# define CASES_"$1" "
- for (i=cmd_range;i>0;i--) {
- print(" "$1"_M"i",") >tokout
- print(" "fix_typ",\t\t/* "$1"_M"i" */") >lgout
- def=def"case "$1"_M"i":"
- }
- for (i=0;i<=cmd_range;i++) {
- print(" "$1"_"i",") >tokout
- print(" "fix_typ",\t\t/* "$1"_"i" */") >lgout
- def=def"case "$1"_"i":"
- }
- def=def"\n"
- }
- print(" "$1",") >tokout
- print(" "typ",\t\t/* "$1" */") >lgout
- }
- #}}}
- #{{{ handle check sum
- $3=="COM" { check = ( check + 1 ) % 1024 }
- $3=="COM_C" { check = ( check + 2 ) % 1024 }
- $3=="COM_I" { check = ( check + 4 ) % 1024 }
- $3=="COM_A" { check = ( check + 16 ) % 1024 }
- $3=="COM_II" { check = ( check + 32 ) % 1024 }
- $3=="COM_ID" { check = ( check + 64 ) % 1024 }
- $3=="COM_P" { check = ( check + 128 ) % 1024 }
- $3=="COM_IP" { check = ( check + 256 ) % 1024 }
- $3=="COM_IIP" { check = ( check + 512 ) % 1024 }
- #}}}
- END {
- # {{{ print end of token type
- print(" DUMMYTOKEN\n } TOKEN;") >tokout
- print("# define TOKEN_TYPE_CHECK "0+check) >tokout
- print("# define FIXED_COMMAND_RANGE "0+cmd_range) >tokout
- printf(def) >tokout
- print("#endif") >tokout
- # }}}
- # {{{ end command type information
- print(" COM") >lgout
- print(" };") >lgout
- print("#else") >lgout
- print(" extern COM_TYPES cmd_type[];") >lgout
- print("#endif") >lgout
- # }}}
- }
-